/**
 * 补0
 * @param {*} num 数字
 * @param {*} n 补零后总位数
 */
export function PrefixZero(num: any, n: any) {
  return (Array(n).join('0') + num).slice(-n);
}
/**
 * 格式化时间
 * @param {*} time 时间
 * @param {*} boolean 时间格式 true:yyyy-MM-dd hh:mm:ss,false:yyyy-MM-dd
 * @param {*} delimiter 分隔符 - || / || 'zh'
 */
export function formatDate(time: any, boolean: any = true, delimiter: any = "-") {
  if (!time) {
    return '-';
  }
  const date = new Date(time);
  const year = date.getFullYear();
  const month = PrefixZero(date.getMonth() + 1, 2);
  const day = PrefixZero(date.getDate(), 2);
  if (boolean) {
    const hour = PrefixZero(date.getHours(), 2);
    const minute = PrefixZero(date.getMinutes(), 2);
    const second = PrefixZero(date.getSeconds(), 2);

    switch (delimiter) {
      case '-':
        return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
      case '/':
        return `${year}/${month}/${day} ${hour}:${minute}:${second}`;
      case 'zh':
        return `${year}年${month}月${day}日 ${hour}点${minute}分${second}秒`;
      case ' ':
        return `${year}${month}${day}${hour}${minute}${second}`;
      default:
        return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
    }

  } else {
    switch (delimiter) {
      case '-':
        return `${year}-${month}-${day}`;
      case '/':
        return `${year}/${month}/${day}`;
      case 'zh':
        return `${year}年${month}月${day}日`;
    }
  }
}

/**
 * 获取当前时间
 * @param {*} boolean 时间格式 true:yyyy-MM-dd hh:mm:ss,false:yyyy-MM-dd
 */
export function getNowDate(boolean = true) {
  const now = new Date();
  return formatDate(now, boolean);
}